define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'tixian/index' + location.search,
                    add_url: 'tixian/add',
                    // edit_url: 'tixian/edit',
                    // del_url: 'tixian/del',
                    multi_url: 'tixian/multi',
                    import_url: 'tixian/import',
                    table: 'tixian',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'order', title: __('Order'), operate: 'LIKE'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
                        {field: 'times', title: __('Times')},

                        {field: 'operate', title: __('Operate'),table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    title: __('确认打款'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-check',
                                    url: 'tixian/successtx',
                                    confirm: '确认已经成功打款',
                                    success: function (data, ret) {
                                        location.reload()
                                    },
                                    visible: function (row) {

                                        //返回true时按钮显示,返回false隐藏
                                        if (row.status==0){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },

                                },
                                {
                                    name: 'ajax',
                                    title: __('驳回'),
                                    classname: 'btn btn-xs btn-primary btn-magic btn-ajax',
                                    icon: 'fa fa-close',
                                    url: 'tixian/bohuitixian',
                                    confirm: '确认驳回提现?',
                                    success: function (data, ret) {
                                        location.reload()
                                    },
                                    visible: function (row) {

                                        //返回true时按钮显示,返回false隐藏
                                        if (row.status==0){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },

                                },
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
